import java.io.File;
import java.math.BigDecimal;
import java.util.Date;

import org.simpleframework.xml.Serializer;
import org.simpleframework.xml.convert.AnnotationStrategy;
import org.simpleframework.xml.convert.Registry;
import org.simpleframework.xml.convert.RegistryStrategy;
import org.simpleframework.xml.core.Persister;
import org.simpleframework.xml.strategy.Strategy;

import Model.Autor;
import Model.Autorzy;
import Model.Baza;
import Model.FakeConverter;
import Model.MyMatcher;
import Model.Pojazdy;
import Model.Samochod;
import Model.Wlasciciel;
import Model.Wlasciciele;



public class Main2 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//Registry registry = new Registry();
		//Strategy strategy = new RegistryStrategy(registry);
		//Serializer serializer = new Persister(strategy);
		Strategy strategy = new AnnotationStrategy();
		Serializer serializer = new Persister(strategy);
		
		File source = new File("autorzyin.xml");

		try {
			//registry.bind(Wlasciciel.class, FakeConverter.class);
			Baza baza = serializer.read(Baza.class, source);
			baza.mapping();
			System.out.println(baza);
			
			baza.getPojazdy().getById("s1").getWlasciciel().setWlasciciel_id("Blalalala");
			baza.getAutorzy().addAuthor("Grzesiu", "Garus", 178900);
			baza.getWlasciciele().addOwner("Stefan", "Zajebisty");
			baza.getPojazdy().addVehicle("w1", "pierdolot", "sdsds", 1678, 2000, 5);
			baza.getPojazdy().addVehicle(baza.getWlasciciele().getById("w6"), "pierdolot", "sdsds", 1678, 2000, 5);
			BigDecimal s = new BigDecimal(100);
			baza.getWarsztat().getCzesci().addPart(baza.getWarsztat().getUslugi().getNaprawy().getById("n7"), "dupa", "dupa", "dupa", 5, s);
			//baza.beforeSave();
			baza.getWarsztat().getUslugi().getNaprawy().addFix(baza.getPojazdy().getById("s1"), "sdsdsd", new Date(), s);
			baza.getWarsztat().getUslugi().getPrzeglady().addCheck(baza.getPojazdy().getById("s1"), "Tak", new Date(), "brak", s);
			File result = new File("result.xml");

			serializer.write(baza, result);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}


